<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="收支项目管理">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <script>
        jQuery(function () {
            fixTableOperatorButton();
        });

        layui.use(['form', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;


            table.on('toolbar(table)', function (obj) {
                let data = obj.data;
                if (obj.event === 'add') {
                    openTab("新增收支项目", "${baseUrl}budget/budgetProjectNew.action");
                }
            });

            table.on('tool(table)', function (obj) {
                let data = obj.data;
                if (obj.event === 'edit') {
                    openTab("编辑收支项目", "${baseUrl}budget/budgetProjectEdit.action?id="+data.id);
                } else if (obj.event === 'delete') {
                    layer.confirm('删除项目《'+data.name+'》?', {icon: 3, title:'删除项目'}, function(index){
                        tipLoad();
                        post("${baseUrl}budget/budgetProject/delete.action",data, function (resp) {
                            closeAll();
                            if (resp.code == 1){
                                tip("删除成功");
                                renderTable();
                            } else {
                                tip(resp.msg);
                            }
                        });
                    });
                }
            });

            form.on('submit(search)', function (data) {
                let json = data.field;
                table.reload('table',{
                    where: json
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                return false;
            });
            renderTable();
        });

        function renderTable() {
            layui.table.render({
                id:'table',
                elem: '#table',
                toolbar: '#tableToolBar',
                defaultToolbar:[],
                url: "${baseUrl}budget/budgetProject/getList.action?time="+(new Date()).valueOf(),
                cols: [[
                    {type: "numbers"},
                    {field: 'id', width: 10, title: 'ID',hide:true},
                    {field: 'name', title: '名称',style:"font-size:12px;"},
                    {field: 'type', title: '收支类别',style:"font-size:12px;", templet:function (d) {
                        return d.type == 1 ? "收入" : "支出";
                    }},
                    {field: 'remark', title: '备注',style:"font-size:12px;"},
                    {title: '操作', minWidth: 80, fixed:'right', templet: '#operBar'},
                ]],
                limit: 10,
                page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    ,groups: 5 //只显示 5 个连续页码
                    ,first: false //不显示首页
                    ,last: false //不显示尾页
                },
                done: function(res, curr, count){
                }
            });
        }

    </script>

</html:header>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">收支类别</label>
                    <div class="layui-input-inline">
                        <select name="searchType">
                            <option value="">全部</option>
                            <option value="1">收入</option>
                            <option value="2">支出</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">其他信息</label>
                    <div class="layui-input-inline">
                        <input type="text" name="search" id="search" placeholder="名称、备注" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <a class="layui-btn" lay-submit="" lay-filter="search">
                        <i class="layui-icon layui-icon-search"></i>
                    </a>
                </div>
            </div>
        </form>

        <div class="horizon-line"></div>

        <table class="layui-hide" id="table" lay-filter="table" lay-size="sm"></table>

        <script type="text/html" id="tableToolBar">
            <div class="layui-inline">
                <a class="layui-btn" lay-event="add">新增</a>
            </div>
        </script>

        <script type="text/html" id="operBar">
            <a class="layui-btn layui-btn-xs table-operator" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger table-operator" lay-event="delete">删除</a>
        </script>
    </div>
</div>

<html:loading tip="处理中..." />
</body>
</html>